import { createRouter, createWebHashHistory ,createWebHistory} from 'vue-router'
import layout from '@/layout'
import UserManageRouter from './modules/UserManage'
import RoleListRouter from './modules/RoleList'
import PermissionListRouter from './modules/PermissionList'
import AdminManageRouter from './modules/AdminManage'
import flowerManageRouter from './modules/FlowerManage'
import flowerTypeRouter from './modules/FlowerType'
import UnshippedCommodityOrderManage from './modules/UnshippedCommodityOrderManage'
import shippedCommodityOrderManage from './modules/shippedCommodityOrderManage'
import completedCommodityOrderManage from './modules/completedCommodityOrderManage'
import storeRevenue from './modules/storeRevenue'
import store from '@/store'
/**
 * 私有路由表的常规写法
 */
//  const privateRoutes = [
//   {
//     path: '/admin',
//     component: layout,
//     redirect: '/admin/manage',
//     meta: {
//       title: 'manage',
//       icon: 'article'
//     },
//     children: [
//       {
//         path: '/admin/manage',
//         component: () => import('@/views/admin-manage'),
//         meta: {
//           title: 'adminManage',
//           icon: 'article-ranking'
//         }
//       },
//       {
//         path: '/admin/role',
//         component: () => import('@/views/role-list/index'),
//         meta: {
//           title: 'roleList',
//           icon: 'role'
//         }
//       },
//       {
//         path: '/admin/permission',
//         component: () => import('@/views/permission-list/index'),
//         meta: {
//           title: 'permissionList',
//           icon: 'permission'
//         }
//       },
//       {
//         path: '/admin/info/:id',
//         name: 'userInfo',
//         component: () => import('@/views/user-info/index'),
//         meta: {
//           title: 'userInfo'
//         }
//       },
//       {
//         path: '/admin/import',
//         name: 'import',
//         component: () => import('@/views/import/index'),
//         meta: {
//           title: 'excelImport'
//         }
//       }
//     ]
//   },
//   {
//     path: '/flower',
//     component: layout,
//     redirect: '/flower/manage',
//     meta: {
//       title: 'flower',
//       icon: 'personnel'
//     },
//     children: [
//       {
//         path: '/flower/manage',
//         component: () => import('@/views/flower-manage/index'),
//         meta: {
//           title: 'flowerManage',
//           icon: 'personnel-manage'
//         }
//       },
//       {
//         path: '/flower/type',
//         component: () => import('@/views/flower-type/index'),
//         meta: {
//           title: 'flowerType',
//           icon: 'personnel-manage'
//         }
//       },
//     ]
//   },
//   {
//     path: '/user',
//     component: layout,
//     redirect: '/user/manage',
//     meta: {
//       title: 'user',
//       icon: 'personnel'
//     },
//     children: [
//       {
//         path: '/user/manage',
//         component: () => import('@/views/user-manage/index'),
//         meta: {
//           title: 'userManage',
//           icon: 'personnel-manage'
//         }
//       },
//     ]
//   },
//   {
//     path: '/commodityOrder',
//     component: layout,
//     redirect: '/commodityOrder/manage',
//     meta: {
//       title: 'commodityOrder',
//       icon: 'article-ranking'
//     },
//     children: [
//       {
//         path: '/commodityOrder/manage',
//         component: () => import('@/views/commodityOrder/index'),
//         meta: {
//           title: 'commodityOrderManage',
//           icon: 'article-ranking'
//         }
//       },
//     ]
//   },
// ]


/**
 * 私有路由表的新写法（为了权限的写法）
 */
export const privateRoutes = [
    storeRevenue,
    UserManageRouter,
    RoleListRouter,
    PermissionListRouter,
    AdminManageRouter,
    flowerManageRouter,
    flowerTypeRouter,
    UnshippedCommodityOrderManage,
    shippedCommodityOrderManage,
    completedCommodityOrderManage
]
/**
 * 公开路由表
 */
export const publicRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index')
  },
  {
    path: '/',
    // 注意：带有路径“/”的记录中的组件“默认”是一个不返回 Promise 的函数
    component: layout,
    redirect: '/profile',
    children: [
      {
        path: '/profile',
        name: 'profile',
        component: () => import('@/views/profile/index'),
        meta: {
          title: 'profile',
          icon: 'el-icon-user'
        }
      },
      {
        path: '/dialog',
        name: 'dialog',
        component: () => import('@/views/DialogPage/index'),
        meta: {
          title: 'dialog',
          icon: 'el-icon-user'
        }
      },
      {
        path: '/404',
        name: '404',
        component: () => import('@/views/error-page/404')
      },
      {
        path: '/401',
        name: '401',
        component: () => import('@/views/error-page/401')
      }
    ]
  }
]

/**
 * 初始化路由表
 */
export function resetRouter() {
  if (
    store.getters.userInfo &&
    store.getters.userInfo.permissions
  ) {
    const menus = store.getters.userInfo.permissions
    menus.forEach(menu => {
      router.removeRoute(menu)
    })
  }
}


const router = createRouter({
  history: createWebHistory(process.env.BASE_URL),
  routes: publicRoutes
})


export default router